var express = require('express');
var router = express.Router();
var Ajax = require('../helper/superagent');
var Host = require('../config/host');
var Promise = require('bluebird');

router.post('*',function(req,res){
  try{
    Promise.resolve(
      Ajax.request('post', Host.common, req.url, "auth")
      .send(req.body)
    ).then(function(data){
      if(data && data.status === 200){
        res.json(data.text);
      }else{
        res.json({
          responseCode: -1,
          responseMessage: '接口异常，请重试'
        })
      }
    })
  }catch(err){
    console.log(err)
    res.json({
      responseCode: -1,
      responseMessage: '接口异常，请重试'
    })
  }
})

// router.get('*',function(req,res){
//   ApiAction.get(req.url,function(data){
//     res.json(data);
//   })
// })

module.exports = router;